home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / C-D / DeveloperStax.cpt / Developer Stack 1.1 / card_4883.txt < prev    next >
Text File  |  1989-02-26  |  2KB  |  63 lines

  1. -- card: 4883 from stack: in.1
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 2202
  5. -- name: LastPathComponent
  6. ----- HyperTalk script -----
  7. function LastPathComponent name
  8. repeat with i = the length of name down to 1
  9.   if character i of name is ":" then exit repeat
  10. end repeat
  11. if i is 1 then
  12.   if first character of name is ":" then
  13.     put 2 into i
  14.   end if
  15. else
  16.   add 1 to i -- skip the colon
  17. end if
  18. put empty into lastpath
  19. repeat with j = i to the length of name
  20.   put character j of name after lastpath
  21. end repeat
  22. return lastpath
  23. end LastPathComponent
  24.  
  25.  
  26. -- part contents for background part 2
  27. ----- text -----
  28. --
  29. -- LastPathComponent -- given a file pathname, returns the last
  30. -- component i.e. whatever comes after the last colon, if anything.
  31. -- From Dewi Williams
  32. --
  33. function LastPathComponent name
  34.   -- scan backwards for the last colon.
  35.   repeat with i = the length of name down to 1
  36.     if character i of name is ":" then exit repeat
  37.   end repeat
  38.   
  39.   if i is 1 then
  40.     -- Name was of the form ":thing" or "thing". Check for leading
  41.     -- colon, and adjust if necessary. Done for generality.
  42.     if first character of name is ":" then
  43.       put 2 into i
  44.     end if
  45.   else
  46.     add 1 to i -- skip the colon
  47.   end if
  48.   
  49.   -- Name was of the form "Thing:otherthing". Return "otherThing".
  50.   put empty into lastpath
  51.   repeat with j = i to the length of name
  52.     put character j of name after lastpath
  53.   end repeat
  54.   return lastpath
  55. end LastPathComponent
  56.  
  57. -- part contents for background part 3
  58. ----- text -----
  59. LastPathComponent
  60.  
  61. -- part contents for background part 10
  62. ----- text -----
  63. 1